package com.glasses.business.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.base.MyBaseAdapter;
import com.glasses.business.entity.Address;
import com.glasses.business.entity.User;
import com.glasses.business.inter.OnItemClick;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/6
 * Version：1.0
 */

public class AddrAdapter extends MyBaseAdapter<Address, AddrAdapter.ViewHolder> {


    public AddrAdapter(Activity context, List data) {
        super(context, data);
    }

    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_addr, null));
    }

    @Override
    protected void onBindViewHolder_(ViewHolder holder, int position) {
        if (data != null && data.size() > 0) {
            final Address address = data.get(position);
            holder.addrName.setText(address.getReceiver());
            holder.addrPhone.setText(address.getPhone());
            holder.addrPlace.setText(address.getAddress() + address.getDetailAddress());
            switch (address.getStatus()) {
                case 0:
                    holder.addrDefaultImg.setImageResource(R.mipmap.icon_xz_copy);
                    break;
                case 1:
                    holder.addrDefaultImg.setImageResource(R.mipmap.icon_xztb);
                    break;
            }
            holder.addrDel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClick.onItemClick(0, address);
                }
            });
            holder.addrEdit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClick.onItemClick(1, address);
                }
            });
            holder.addrDefault.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClick.onItemClick(2, address);
                }
            });
            holder.addressLL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClick.onItemClick(3, address);
                }
            });
        }
    }

    private OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

//    @OnClick({R.id.addrDefault, R.id.addrEdit, R.id.addrDel})
//    public void onClick(View view) {
//        switch (view.getId()) {
//            case R.id.addrDefault:
//                break;
//            case R.id.addrEdit:
//                break;
//            case R.id.addrDel:
//
//                break;
//        }
//    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.addrName)
        TextView addrName;
        @InjectView(R.id.addrPhone)
        TextView addrPhone;
        @InjectView(R.id.addrPlace)
        TextView addrPlace;
        @InjectView(R.id.addrDefaultImg)
        ImageView addrDefaultImg;
        @InjectView(R.id.addrDefault)
        LinearLayout addrDefault;
        @InjectView(R.id.addrEdit)
        LinearLayout addrEdit;
        @InjectView(R.id.addrDel)
        LinearLayout addrDel;
        @InjectView(R.id.addressLL)
        LinearLayout addressLL;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
